//
//  JOStatuseFrame.m
//  微博
//
//  Created by song on 15/1/14.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "JOStatuseFrame.h"
#import "JOStatus.h"
#define JONameFont [UIFont systemFontOfSize:14]

@implementation JOStatuseFrame



-(CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
    NSDictionary *attrs =@{NSFontAttributeName :font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}


-(void)setStatus:(JOStatus *)status
{
    
    _status = status;
    
    CGFloat padding = 10;
    CGFloat iconX= padding;
    CGFloat iconY =padding;
    CGFloat iconW = 30;
    CGFloat iconH = 30;
    
    self.iconF = CGRectMake(iconX, iconY, iconW, iconH);
    
    
    
    CGSize nameMAXSize = CGSizeMake(MAXFLOAT, MAXFLOAT);
    
    CGSize nameSize= [self sizeWithText:status.name font:JONameFont maxSize:nameMAXSize];
    
    CGFloat nameX = CGRectGetMaxX(self.iconF) +padding;
    CGFloat nameY = iconY + (iconH-nameSize.height)*0.5;
    self.nameF = CGRectMake(nameX, nameY, nameSize.width, nameSize.height);
    
    
    CGFloat vipX = CGRectGetMaxX(self.nameF) +padding;
    CGFloat vipY =nameY;
    CGFloat vipW = 14;
    CGFloat vipH = 14;
    self.vipF = CGRectMake(vipX, vipY, vipW, vipH);
    
    CGFloat textX = iconX;
    CGFloat textY =CGRectGetMaxY(self.iconF)+padding;
    CGSize textSize =[self sizeWithText:self.status.text font:JONameFont maxSize:CGSizeMake(300, MAXFLOAT)];
    self.textF = CGRectMake(textX, textY, textSize.width, textSize.height);
    
    
    if(self.status.picture)
    {
        CGFloat picX=  textX;
        CGFloat picY =CGRectGetMaxY(self.textF) +padding;
        CGFloat picH = 100;
        CGFloat picW = 100;
        self.pictureF =CGRectMake(picX, picY, picW, picH);
        self.cellHeight = CGRectGetMaxY(self.pictureF);
        
    }else{
        self.cellHeight = CGRectGetMaxY(self.textF);
    }

    
    
}
@end
